local lspconfig = package.loaded["lspconfig"]

-- List of servers to ignore during install
local ignore_install = {}

-- Helper function to find if value is in table.
local function table_contains(table, value)
    for _, v in ipairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

-- Build a list of lsp servers to install minus the ignored list.
local all_servers = {
    "lua_ls",
    -- "rust_analyzer",
    'bashls',


    'vimls',

    'cssls',
    'ts_ls',


    'jsonls',


    'bashls',


    'astro',
    'svelte',
}
for _, s in ipairs(lspconfig.servers) do
    if not table_contains(ignore_install, s) then
        table.insert(all_servers, s)
    end
end

require("mason-lspconfig").setup({
    ensure_installed = all_servers,
    automatic_installation = true,
})

-- require('mason-tool-installer').setup {

--     -- a list of all tools you want to ensure are installed upon
--     -- start
--     ensure_installed = {



--         -- you can turn off/on auto_update per tool
--         { 'bash-language-server', auto_update = true },

--         'lua-language-server',
--         'vim-language-server',

--         'stylua',
--         'shellcheck',
--         'editorconfig-checker',

--         'jsonlint',
--         'json-to-struct',

--         'shellcheck',
--         'shfmt',

--         'astro-language-server',
--         'svelte-language-server',

--     },

--     -- if set to true this will check each tool for updates. If updates
--     -- are available the tool will be updated. This setting does not
--     -- affect :MasonToolsUpdate or :MasonToolsInstall.
--     -- Default: false
--     auto_update = true,

--     -- automatically install / update on startup. If set to false nothing
--     -- will happen on startup. You can use :MasonToolsInstall or
--     -- :MasonToolsUpdate to install tools and check for updates.
--     -- Default: true
--     run_on_start = true,

--     -- set a delay (in ms) before the installation starts. This is only
--     -- effective if run_on_start is set to true.
--     -- e.g.: 5000 = 5 second delay, 10000 = 10 second delay, etc...
--     -- Default: 0
--     start_delay = 3000, -- 3 second delay

--     -- Only attempt to install if 'debounce_hours' number of hours has
--     -- elapsed since the last time Neovim was started. This stores a
--     -- timestamp in a file named stdpath('data')/mason-tool-installer-debounce.
--     -- This is only relevant when you are using 'run_on_start'. It has no
--     -- effect when running manually via ':MasonToolsInstall' etc....
--     -- Default: nil
--     debounce_hours = 5, -- at least 5 hours between attempts to install/update

--     -- By default all integrations are enabled. If you turn on an integration
--     -- and you have the required module(s) installed this means you can use
--     -- alternative names, supplied by the modules, for the thing that you want
--     -- to install. If you turn off the integration (by setting it to false) you
--     -- cannot use these alternative names. It also suppresses loading of those
--     -- module(s) (assuming any are installed) which is sometimes wanted when
--     -- doing lazy loading.
--     integrations = {
--         ['mason-lspconfig'] = true,
--         ['mason-null-ls'] = true,
--         ['mason-nvim-dap'] = true,
--     },
-- }
